//断言
// 类型断言好比其它语言里的类型转换（类型检测），但是不进行特殊的数据检查和解构。
//断言有两种形式

//泛型 标识 <>  要和断言区分开来

// 1.尖括号”语法：
// let someValue: any = "this is a string";
// let strLength: number = (<string>someValue).length;
// console.log(strLength);


// 2.as 语法
// let someValue: any = "this is a string";
// let strLength: number = (someValue as string).length;

//检测是否是数值类型
const Num = 12 as number

const str = "胡子瑜" as string
type STR = typeof str  //检测数据类型
console.log(str);

//类型: 类型是一种数据格式  不是指  只有值才能被打印

type Allum = number
let nwenuber: Allum = 12
if (nwenuber == 12) {
    console.log("是数字");

}

//枚举
// enum Color {Rad,Green,Blue}
// console.log(Color);

// let c:Color=Color.Green;
// console.log(c,'c'); //打印出来的下标


enum Color { Red = 1, Green = 2, Blue = 4 }
console.log(Color);
console.log(Color[2]);



// enum Color {Red="1",Green="2",Blue="4"}
// console.log(Color);


let obj = {
    a: 111,
    b: 222,
    c: 333
}

for (var i in obj) {
    console.log(obj, 'obj');
    console.log(i, 'i');
    console.log(obj[i]);


}


//联合类型  |
let a: number | string | boolean = false

let obj2: { a: number, c: boolean } | {} | { z: string } = {
    a: 1,
    b: '1',
    c: false
}
console.log(obj2);

// ? 可选  让类型不为必须校验
let obj3: { a: number, b?: boolean } | { z: string } = {
    a: 1
}

//这里只能匹配同一种数据类型
let thisArr: string[] | number[] | boolean[] = [false, true, false, true]

let thisass: {}[] | {
    a: number, b: string
}[] = [{}, { a: 1, b: 2 }]

console.log(thisass);

let isDone: boolean = false

let decLiteral: number = 6

let user: string = '胡子瑜'
user = '123456'

let user1: string = `胡子瑜`
let age: number = 18
let sentence: string = `hello,my name is ${user1} I'll be${age + 1} years old next month`



let list: number[] = [1, 2, 3]

let list2: Array<number> = [1, 2, 3]


// let x: [string, number];
// x = ['胡子瑜', 10]  //✔
// x = [10,'hello']   //❌


let notsure: any = 4
// notsure = 'this a number'
console.log(notsure);

let list11: any[] = [1, true, '111']
console.log(list11);
list11[1] = 100

function sun(a: number, b: number) {
    return a + b
}
console.log(sun(11, 22));

// for (var iw = 0; iw < 10; iw++) {
//     (function(iw){
//         setTimeout(function(){
//             console.log(iw);
            
//         },100*iw)
//     })(iw)
    
// }

function f(input:boolean){
    let a = 100
    let b1=200
    if(input){
        let b1 = a+1
        return b1
    }
    return b1
}
